package com.heihei.authority.core.validate.code;

import com.heihei.authority.core.properties.MySecurityProperties;
import com.heihei.authority.core.validate.code.image.ImageCodeGenerator;
import com.heihei.authority.core.validate.code.sms.DefaultSmsCodeSender;
import com.heihei.authority.core.validate.code.sms.SmsCodeSender;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 *  图形验证码 Bean配置
 *
 * @version 1.0
 * @since JDK1.8
 * @author duanhengfei
 * @date 2021年04月11日 11:02:53
 */
@Configuration
public class ValidateCodeBeanConfig {
    @Resource
    private MySecurityProperties mySecurityProperties;

    /**
     * 图片验证码
     * 不存在 imageCodeGenerator 时，创建这个Bean
     *
     * @param  
     * @Return {@link ValidateCodeGenerator}
     * @throws 
     * @author duanhengfei
     * @date 2021年04月11日 10:52:55
     */
    @Bean
    @ConditionalOnMissingBean(name = "imageValidateCodeGenerator")
    public ValidateCodeGenerator imageValidateCodeGenerator() {
        ImageCodeGenerator codeGenerator = new ImageCodeGenerator();
        codeGenerator.setMySecurityProperties(mySecurityProperties);
        return codeGenerator;
    }


    @Bean
    @ConditionalOnMissingBean(SmsCodeSender.class)
    public SmsCodeSender smsCodeSender() {
        return new DefaultSmsCodeSender();
    }
}
